package cn.itcast.thread;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class scheduledThreadExecutorTest {

    public static void main(String[] args) {
        /**
         * 创建一个大小无限的线程池。此线程池支持定时以及周期性执行任务的需求。
         */
        ScheduledThreadPoolExecutor exec =new ScheduledThreadPoolExecutor(1);

        exec.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("===================");
            }
        }, 1000, 5000, TimeUnit.MILLISECONDS);

        exec.scheduleAtFixedRate(new Runnable(){//每隔一段时间打印系统时间，证明两者是互不影响的

            @Override
            public void run() {
                // TODO Auto-generated method stub
                System.out.println(System.nanoTime());

            }}, 1000, 2000, TimeUnit.MILLISECONDS);
    }
}
